function contains(arr, val) {
	return arr.some((a) => a === val);
}

function any(arr) {
	return arr[~~(Math.random() * arr.length)];
}

function pick(arr, count) {
	// var arrayNum = ['One', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
	// console.log( pick(3) ); // -> [ 'One', 'four', 'seven' ]
	const tmp = arr.slice(arr);
	const res = [];
	for (let i = 0; i < count; i++) {
		const index = Math.floor(Math.random() * tmp.length);
		const removed = tmp.splice(index, 1);
		res.push(removed[0]);
	}
	return res;
}

function shuffle(arr) {
	// var arr = shuffle( [2, 11, 37, 42] );
	let rnd;
	let tmp;
	let len = arr.length;
	const res = arr.slice();
	while (len) {
		rnd = Math.floor(Math.random() * len--);
		tmp = res[len];
		res[len] = res[rnd];
		res[rnd] = tmp;
	}
	arr.length = 0;
	arr = null;
	return res;
}

// function uniq(arr) {
// 	// will also modify & overwrite original array
// 	// var arr = ['a', 'b', 'c', 'c'];
// 	// console.log( uniq(arr) ) //-> ['a', 'b', 'c']
// 	// console.log( arr )       //-> ['a', 'b', 'c']
// 	const len = arr.length;
// 	let i = -1;
// 	while (i++ < len) {
// 		let j = i + 1;
// 		for (; j < arr.length; ++j) {
// 			if (arr[i] === arr[j]) {
// 				arr.splice(j--, 1);
// 			}
// 		}
// 	}
// 	return arr;
// }

function uniq(arr) {
	const res = [...new Set(arr)];
	return res;
}

export { contains, any, pick, shuffle, uniq };
